
/**
 * Playlist class is the class the represents a playlist, using an AVL tree 
 * in order to store the data.
 * 
 * @author <b>Matan Mizrahi,Ofir Naor</b>
 *
 */
public class Playlist extends StringComparator{
	private String name;
	private IntegerComparator intComp;
	private AVLTree songs;
	/**
	 * Constructs a new playlist 
	 * 
	 * @param name
	 */
	public Playlist(String name){
		this.name = name;
		intComp=new IntegerComparator();
		this.songs=new AVLTree(intComp);
	
	}
	/**
	 * Gets the name of the playlist
	 * 
	 * @return the name
	 */
	public String getName(){
		return this.name;
	}

	
	/**
	 * Adding a new song to the playlist
	 * 
	 * @param song the song which we want to add to the songs
	 * @author <b>Matan Mizrahi,Ofir Naor</b>
	 */
	public void add(Song song) {
		if (song!=null){
			this.songs.add(song.getLength(),song);
			song.getPlaylists().addFirst(this);//inserting the playlist to the song's playlist
		}
	}
	/**
	 * Removes song from the playlist
	 * 
	 * @param song which we want to remove from the songs
	 * @author <b>Matan Mizrahi,Ofir Naor</b>
	 */
	public void remove(Song song) {
		this.songs.remove(song.getLength());
	}
	/**
	 * Finds the song in the given length
	 * 
	 * @param length the length of the song which we want to find
	 * @return null if the song doesn't exist.Otherwise, returns the song
	 * @author <b>Matan Mizrahi,Ofir Naor</b>
	 */
	public Song find(int length) {
		return (Song)this.songs.find(length);
			

	}
	/**
	 * A method that finds the k'th song in the playlist
	 * @param k the order number of the song we want to find
	 * @return null if the songs is empty or if k is larger than the number of songs. 
	 * otherwise return the k'th song in the songs
	 * @author <b>Matan Mizrahi,Ofir Naor</b>
	 */
	public Song findKthSong(int k){
		return (Song)this.songs.findKthElement(k);
	}
	/**
	 * A method to return a linked songs of songs from given ranges.
	 * 
	 * @param k the order of the first song in the linked songs	
	 * @param hthe order of the last song in the linked songs
	 * @return a linked with h-k songs
	 */
	public LinkedList getKthtillHthSongs(int k,int h) {
		return this.songs.getKthTillHth(k,h);
	}
	/**
	 * A method that returns the amount of songs in the playlist
	 * 
	 * @return -1 if songs is empty, otherwise return the number of songs in the songs
	 * @author <b>Matan Mizrahi,Ofir Naor</b> 
	 */
	public int size(){
		return this.songs.size();
	}
}
